Skip to contentSkip to conversation

Change in openvpn[master]: Introduce report_command_status helper function

Openvpn-devel In review plaisthos (Code Review) 3 participants 6 messages Nov 20, 2023 – Nov 21, 2023 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1700480182000.I91f739f5cb43386b2ce767cf3603a76e6b93e216@...2715...

#1 lore raw

Attention is currently required from: flichtenheld.

Hello flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/450?usp=email

to review the following change.

Change subject: Introduce report_command_status helper function
......................................................................

Introduce report_command_status helper function

Instead of repeating near identical code several times in manage.c, use a small helper function instead.

Change-Id: I91f739f5cb43386b2ce767cf3603a76e6b93e216
---
M src/openvpn/manage.c

1 file changed, 21 insertions(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/50/450/1

src/openvpn/manage.c +21 -24
index feb62b2..3cf392a 100644
@@ -284,6 +284,24 @@
 #endif
 }
 
+
+/**
+ * Small function to report the success or failure of a command to
+ * the management interface
+ */
+static void
+report_command_status(const bool status, const char *command)
+{
+    if (status)
+    {
+        msg(M_CLIENT, "SUCCESS: %s command succeeded", command);
+    }
+    else
+    {
+        msg(M_CLIENT, "ERROR: %s command failed", command);
+    }
+}
+
 static void
 man_delete_unix_socket(struct management *man)
 {
@@ -974,14 +992,7 @@
                                         NULL,
                                         man->connection.in_extra);
                 man->connection.in_extra = NULL;
-                if (status)
-                {
-                    msg(M_CLIENT, "SUCCESS: client-auth command succeeded");
-                }
-                else
-                {
-                    msg(M_CLIENT, "ERROR: client-auth command failed");
-                }
+                report_command_status(status, "client_auth");
             }
             else
             {
@@ -1260,14 +1271,7 @@
     if (man->persist.callback.proxy_cmd)
     {
         const bool status = (*man->persist.callback.proxy_cmd)(man->persist.callback.arg, p);
-        if (status)
-        {
-            msg(M_CLIENT, "SUCCESS: proxy command succeeded");
-        }
-        else
-        {
-            msg(M_CLIENT, "ERROR: proxy command failed");
-        }
+        report_command_status(status, "proxy");
     }
     else
     {
@@ -1281,14 +1285,7 @@
     if (man->persist.callback.remote_cmd)
     {
         const bool status = (*man->persist.callback.remote_cmd)(man->persist.callback.arg, p);
-        if (status)
-        {
-            msg(M_CLIENT, "SUCCESS: remote command succeeded");
-        }
-        else
-        {
-            msg(M_CLIENT, "ERROR: remote command failed");
-        }
+        report_command_status(status, "remote");
     }
     else
     {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/450?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I91f739f5cb43386b2ce767cf3603a76e6b93e216
Gerrit-Change-Number: 450
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/450?usp=email )

Change subject: Introduce report_command_status helper function
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/450?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I91f739f5cb43386b2ce767cf3603a76e6b93e216
Gerrit-Change-Number: 450
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Mon, 20 Nov 2023 11:57:47 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw

PATCH 1/1 Introduce report_command_status helper function

In reply to a message not in the archive

From: Arne Schwabe <[email protected]...>

Instead of repeating near identical code several times in manage.c, use a small helper function instead.

Change-Id I91f739f5cb43386b2ce767cf3603a76e6b93e216

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/450
This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

src/openvpn/manage.c +21 -24
index feb62b2..3cf392a 100644
@@ -284,6 +284,24 @@
 #endif
 }
 
+
+/**
+ * Small function to report the success or failure of a command to
+ * the management interface
+ */
+static void
+report_command_status(const bool status, const char *command)
+{
+    if (status)
+    {
+        msg(M_CLIENT, "SUCCESS: %s command succeeded", command);
+    }
+    else
+    {
+        msg(M_CLIENT, "ERROR: %s command failed", command);
+    }
+}
+
 static void
 man_delete_unix_socket(struct management *man)
 {
@@ -974,14 +992,7 @@
                                         NULL,
                                         man->connection.in_extra);
                 man->connection.in_extra = NULL;
-                if (status)
-                {
-                    msg(M_CLIENT, "SUCCESS: client-auth command succeeded");
-                }
-                else
-                {
-                    msg(M_CLIENT, "ERROR: client-auth command failed");
-                }
+                report_command_status(status, "client_auth");
             }
             else
             {
@@ -1260,14 +1271,7 @@
     if (man->persist.callback.proxy_cmd)
     {
         const bool status = (*man->persist.callback.proxy_cmd)(man->persist.callback.arg, p);
-        if (status)
-        {
-            msg(M_CLIENT, "SUCCESS: proxy command succeeded");
-        }
-        else
-        {
-            msg(M_CLIENT, "ERROR: proxy command failed");
-        }
+        report_command_status(status, "proxy");
     }
     else
     {
@@ -1281,14 +1285,7 @@
     if (man->persist.callback.remote_cmd)
     {
         const bool status = (*man->persist.callback.remote_cmd)(man->persist.callback.arg, p);
-        if (status)
-        {
-            msg(M_CLIENT, "SUCCESS: remote command succeeded");
-        }
-        else
-        {
-            msg(M_CLIENT, "ERROR: remote command failed");
-        }
+        report_command_status(status, "remote");
     }
     else
     {
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: Introduce report_command_status helper function

Skimmed the code, test compiled, not excercised the management interface.

Obvious improvement.

"client-auth" morphed into "client_auth" here, which I took the liberty to change back (checked with Arne, avoid a new round).

Your patch has been applied to the master branch.

commit 57172d84096cc03e4a5a0658b9abb15d4173859d (master)

Author: Arne Schwabe
Date:   Tue Nov 21 11:42:54 2023 +0100
     Introduce report_command_status helper function

     Acked-by: Frank Lichtenheld <[email protected]...>
     Signed-off-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg27525.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/450?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

Change subject: Introduce report_command_status helper function
......................................................................

Introduce report_command_status helper function

Instead of repeating near identical code several times in manage.c, use a small helper function instead.

Change-Id I91f739f5cb43386b2ce767cf3603a76e6b93e216

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg27525.html

---
M src/openvpn/manage.c

1 file changed, 21 insertions(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/50/450/2

src/openvpn/manage.c +21 -24
index feb62b2..27b6f90 100644
@@ -284,6 +284,24 @@
 #endif
 }
 
+
+/**
+ * Small function to report the success or failure of a command to
+ * the management interface
+ */
+static void
+report_command_status(const bool status, const char *command)
+{
+    if (status)
+    {
+        msg(M_CLIENT, "SUCCESS: %s command succeeded", command);
+    }
+    else
+    {
+        msg(M_CLIENT, "ERROR: %s command failed", command);
+    }
+}
+
 static void
 man_delete_unix_socket(struct management *man)
 {
@@ -974,14 +992,7 @@
                                         NULL,
                                         man->connection.in_extra);
                 man->connection.in_extra = NULL;
-                if (status)
-                {
-                    msg(M_CLIENT, "SUCCESS: client-auth command succeeded");
-                }
-                else
-                {
-                    msg(M_CLIENT, "ERROR: client-auth command failed");
-                }
+                report_command_status(status, "client-auth");
             }
             else
             {
@@ -1260,14 +1271,7 @@
     if (man->persist.callback.proxy_cmd)
     {
         const bool status = (*man->persist.callback.proxy_cmd)(man->persist.callback.arg, p);
-        if (status)
-        {
-            msg(M_CLIENT, "SUCCESS: proxy command succeeded");
-        }
-        else
-        {
-            msg(M_CLIENT, "ERROR: proxy command failed");
-        }
+        report_command_status(status, "proxy");
     }
     else
     {
@@ -1281,14 +1285,7 @@
     if (man->persist.callback.remote_cmd)
     {
         const bool status = (*man->persist.callback.remote_cmd)(man->persist.callback.arg, p);
-        if (status)
-        {
-            msg(M_CLIENT, "SUCCESS: remote command succeeded");
-        }
-        else
-        {
-            msg(M_CLIENT, "ERROR: remote command failed");
-        }
+        report_command_status(status, "remote");
     }
     else
     {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/450?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I91f739f5cb43386b2ce767cf3603a76e6b93e216
Gerrit-Change-Number: 450
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/450?usp=email )

Change subject: Introduce report_command_status helper function
......................................................................

Introduce report_command_status helper function

Instead of repeating near identical code several times in manage.c, use a small helper function instead.

Change-Id I91f739f5cb43386b2ce767cf3603a76e6b93e216

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg27525.html

---
M src/openvpn/manage.c

1 file changed, 21 insertions(+), 24 deletions(-)
src/openvpn/manage.c +21 -24
index feb62b2..27b6f90 100644
@@ -284,6 +284,24 @@
 #endif
 }
 
+
+/**
+ * Small function to report the success or failure of a command to
+ * the management interface
+ */
+static void
+report_command_status(const bool status, const char *command)
+{
+    if (status)
+    {
+        msg(M_CLIENT, "SUCCESS: %s command succeeded", command);
+    }
+    else
+    {
+        msg(M_CLIENT, "ERROR: %s command failed", command);
+    }
+}
+
 static void
 man_delete_unix_socket(struct management *man)
 {
@@ -974,14 +992,7 @@
                                         NULL,
                                         man->connection.in_extra);
                 man->connection.in_extra = NULL;
-                if (status)
-                {
-                    msg(M_CLIENT, "SUCCESS: client-auth command succeeded");
-                }
-                else
-                {
-                    msg(M_CLIENT, "ERROR: client-auth command failed");
-                }
+                report_command_status(status, "client-auth");
             }
             else
             {
@@ -1260,14 +1271,7 @@
     if (man->persist.callback.proxy_cmd)
     {
         const bool status = (*man->persist.callback.proxy_cmd)(man->persist.callback.arg, p);
-        if (status)
-        {
-            msg(M_CLIENT, "SUCCESS: proxy command succeeded");
-        }
-        else
-        {
-            msg(M_CLIENT, "ERROR: proxy command failed");
-        }
+        report_command_status(status, "proxy");
     }
     else
     {
@@ -1281,14 +1285,7 @@
     if (man->persist.callback.remote_cmd)
     {
         const bool status = (*man->persist.callback.remote_cmd)(man->persist.callback.arg, p);
-        if (status)
-        {
-            msg(M_CLIENT, "SUCCESS: remote command succeeded");
-        }
-        else
-        {
-            msg(M_CLIENT, "ERROR: remote command failed");
-        }
+        report_command_status(status, "remote");
     }
     else
     {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/450?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I91f739f5cb43386b2ce767cf3603a76e6b93e216
Gerrit-Change-Number: 450
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged